package de.fhd.pms;


import java.awt.Image;
import java.io.*;
import java.util.Date;
import java.util.Vector;

import javax.servlet.*;
import javax.servlet.http.*;

public class ServPmsVisit extends HttpServlet  {
 	private static final long serialVersionUID = 1L;

 private String greeting;
 private String ipcam_adr;
 private String pic_not_id;
 private String pic_unknown;
 //Image	webcamImage;		// Image from Webcam
 //Thread	thread_This;		// Thread for refreshing image

  public void init()
    throws ServletException
  {
    greeting = getInitParameter("greeting");
    ipcam_adr = getInitParameter("ipcam_adr");
    pic_not_id = getInitParameter("pic_not_id");
    pic_unknown = getInitParameter("pic_unknown");
    
  }
  
  @Override
  public void doGet( HttpServletRequest request, HttpServletResponse response )
  throws ServletException, IOException
  {
	  
 
     response.setContentType( "text/html" );
     PrintWriter out = response.getWriter();
     out.println("<html>");
     
     out.println("<head>");
     out.println("<script type='text/javascript' src='Projects/_common/js/dhtml.js'></script>");
     out.println("<script type='text/javascript' src='Projects/_common/js/addons.js'></script>");
     out.println("<title>" + greeting + "</title>");
     out.println("<h1>" + greeting + "</h1>");
     out.println("<h5>"+ "IPCam vlc plugin life rtsp-streaming " + ipcam_adr + "</h5>");
     out.println("</head>");

     out.println("<body onload='window.setTimeout('ZeitAnzeigen()', 1000)'>");
     out.println("<p id='Uhr' class='Uhr'> &nbsp; </p>");
  
     out.println( "<table border>" );
     out.println( "<tr>" );
	     out.println( "<td rowspan='2' >" );
		     out.println("<OBJECT classid='clsid:E23FE9C6-778E-49D4-B537-38FCDE4887D8' " +
		     	     	"codebase='http://downloads.videolan.org/pub/videolan/vlc/latest/win32/axvlc.cab'  " +
		     	     	"width='640' height='480' id='vlc' events='True' name='vlc' ShowStatusBar='True' ShowDisplay='True'> ");
		     out.println("<param name='Src' value="+ ipcam_adr +"/>");
		     out.println("<param name='ShowDisplay' value='True' />");
		     out.println("<param name='AutoLoop' value='True' />");
		     out.println("<param name='AutoPlay' value='True' />");
		     out.println("<param name='Controller' value='True' />");
		     out.println("<param name='Volume' value='100'/>");
		     out.println("<param name='StartTime' value='False'/>");
	// todo: buffer progress bar to be displayed 	    
		     out.println("<param name='ShowStatusBar' value='True'/>"); 
		     out.println("</OBJECT>");
    // todo: picture to be updated dynamically 
		 out.println( "</td>" );
		 out.println( "<td width='30'></td>" );
		 out.println( "<td colspan='2'>" );
		 out.println( "<APPLET code='JavaCam.class' >");  
		 out.println( "<PARAM name='trace' value='1'>");
		 out.println( "<PARAM name='url'  value='http://192.168.178.50/test.jpg'/>");
		 out.println( "<PARAM name='interval' value='1'>");
		 out.println( "</APPLET><br />");
		 //out.println( "<img src="+ pic_not_id +" height='235' width='300' alt='people not identified'/>" );
		 out.println( "</td>" );
		 out.println( "</tr>" );
		 out.println( "<tr>");
		 out.println( "<td width='30'></td>" );
		 out.println( "<td>" );
		 out.println( "<APPLET code='JavaCam.class' >");  
		 out.println( "<PARAM name='trace' value='1'>");
		 out.println( "<PARAM name='url'  value=" + pic_not_id + "/>");
		 //out.println( "<PARAM name='url'  value='http://192.168.178.50/test.jpg'/>");
		 out.println( "<PARAM name='interval' value='1'>");
		 out.println( "</APPLET><br />");
		 //out.println( "<img src="+ pic_unknown +" height='235' width='300' alt='people on net unkown'/>" );
		 out.println( "</td>" );
		 out.println( "</tr>");
		 out.println( "</table>" );
	 out.println( "<p><br />" );
    // todo: table to be updated dynamically
	 out.println( "<table border>" );
     out.println( "<tr>" );
	     out.println( "<td width='50'> Id</td>" );
	     out.println( "<td width='300'> name</td>" );
	     out.println( "<td width='200' > date</td>" );
	     out.println( "<td width='200'> info1</td>" );
	     out.println( "<td width='100'> info2</td>" );
	     out.println( "<td width='100'>  info3</td>" );
	 out.println( "</tr>" );
     out.println( "<tr>" );
 	     out.println( "<td> 1 </td>" );
	     out.println( "<td> unknown </td>" );
	     out.println( "<td> 2</td>" );
	     out.println( "<td> 3</td>" );
	     out.println( "<td> 4</td>" );
	     out.println( "<td> 5</td>" );
	 out.println( "</tr>" );
     out.println( "<tr>" );
		 out.println( "<td> 2 </td>" );
	     out.println( "<td> unknown </td>" );
	     out.println( "<td> 2</td>" );
	     out.println( "<td> 3</td>" );
	     out.println( "<td> 4</td>" );
	     out.println( "<td> 5</td>" );
	 out.println( "</tr>" );
	 out.println( "</table>" );

	 // open "project information" in a new window to avoid reload of vlc rtsp-stream 
	out.println("<script LANGUAGE='JavaScript'>");
	out.println("function openAboutWin()" +
	            "{window.open('about'," +
	    		"'tabwin', 'scrollbars=1,status=0,toolbar=0,resizable=1," +
	    		"width=650,height=480,top=200,left=400'); } ");
	out.println("</script>");
	out.println("<script LANGUAGE='JavaScript'>");
	// open "administrator page" in a new window to avoid reload of vlc rtsp-stream
	out.println("function openAdminWin()" +
	            "{window.open('admin'," +
	    		"'tabwin', 'scrollbars=1,status=0,toolbar=0,resizable=1," +
	    		"width=650,height=480,top=250,left=400'); } ");
	out.println("</script>"); 
	out.println( "<p><br />" );
	// navigator e.g. <a href='admin' target='_blank'>Administrator Page</a>
	out.println( "<a href='index.html'>Logout</a> / <a href='javascript:openAdminWin();'>Administrator Page</a> / " + 
                 "<a href='javascript:openAboutWin();'>Project Information </a>" );
	
	//response.setHeader("Refresh", "1");
    //out.println(new Date().toString());
	out.println("</body>");
	out.println( "</html>" );
    out.close();
     
  }

 
  public void destroy()
  {
    // nothing to do
  }
}
